home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / reuse.lha / reuse / m2c / Sort.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  1KB  |  78 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_Sort
  4. #include "Sort.h"
  5. #endif
  6.  
  7.  
  8. static void QuickSort ARGS((INTEGER Lwb, INTEGER Upb));
  9.  
  10. static Sort_tProcIntInt *G_1_Swap;
  11. static Sort_tProcIntIntBool *G_2_IsLess;
  12.  
  13. static void QuickSort
  14. # ifdef __STDC__
  15. (INTEGER Lwb, INTEGER Upb)
  16. # else
  17. (Lwb, Upb)
  18. INTEGER Lwb, Upb;
  19. # endif
  20. {
  21.   INTEGER i, j;
  22.  
  23.   for (;;) {
  24.     if (Lwb >= Upb) {
  25.       return;
  26.     }
  27.     i = Lwb + 1;
  28.     j = Upb;
  29.     do {
  30.       while (i < Upb && (**G_2_IsLess)(i, Lwb)) {
  31.         INC(i);
  32.       }
  33.       while (Lwb < j && (**G_2_IsLess)(Lwb, j)) {
  34.         DEC(j);
  35.       }
  36.       if (i < j) {
  37.         (**G_1_Swap)(i, j);
  38.       }
  39.     } while (!(i >= j));
  40.     (**G_1_Swap)(Lwb, j);
  41.     QuickSort(Lwb, j - 1);
  42.     Lwb = j + 1;
  43.   } EXIT_1:;
  44. }
  45.  
  46. void Sort_Sort
  47. # ifdef __STDC__
  48. (INTEGER Lwb, INTEGER Upb, Sort_tProcIntIntBool IsLess, Sort_tProcIntInt Swap)
  49. # else
  50. (Lwb, Upb, IsLess, Swap)
  51. INTEGER Lwb, Upb;
  52. Sort_tProcIntIntBool IsLess;
  53. Sort_tProcIntInt Swap;
  54. # endif
  55. {
  56.   Sort_tProcIntInt *L_1;
  57.   Sort_tProcIntIntBool *L_2;
  58.  
  59.   L_1 = G_1_Swap;
  60.   G_1_Swap = &Swap;
  61.   L_2 = G_2_IsLess;
  62.   G_2_IsLess = &IsLess;
  63.   QuickSort(Lwb, Upb);
  64.   G_1_Swap = L_1;
  65.   G_2_IsLess = L_2;
  66. }
  67.  
  68. void BEGIN_Sort()
  69. {
  70.   static BOOLEAN has_been_called = FALSE;
  71.  
  72.   if (!has_been_called) {
  73.     has_been_called = TRUE;
  74.  
  75.  
  76.   }
  77. }
  78.